#include<stdio.h>
struct Student{
	char name[20];
	char num[20];
	int score;
};

int main()
{
	struct Student student[1000];
	int n;
	scanf("%d", &n);
	for(int i=0;i<n;i++)
	{
		scanf("%s%s%d",&student[i].name,&student[i].num,&student[i].score);
	}
	int MAX=student[0].score, pos_MAX=0;
	int MIN=student[0].score, pos_MIN=0;
	int i;
	for(i=1;i<n;i++)
	{
		if(student[i].score>MAX)
		{
			MAX=student[i].score;
			pos_MAX = i;
		}	
		if(student[i].score<MIN)
		{
			MIN=student[i].score;
			pos_MIN = i;
		}  
	}
	printf("%s %s\n%s %s\n", student[pos_MAX].name, student[pos_MAX].num, student[pos_MIN].name, student[pos_MIN].num);
  return 0;
  
}

